import {Component, OnInit, ViewEncapsulation} from '@angular/core';
import {Location} from '@angular/common';
import {ActivatedRoute, Router, Params} from "@angular/router";

import {ToolsService} from "@shared/service/tools/tools.service";

import {NewsService} from "@news/news.service";
import {ArticleCommentVO} from "@interface/index";



@Component({
  selector: 'news-comment',
  templateUrl: './news-comment.component.html',
  styleUrls: ['./news-comment.component.scss'],
  encapsulation: ViewEncapsulation.None
})
export class NewsCommentComponent implements OnInit {
  public comments: ArticleCommentVO[] = [];
  private articleId: number;
  private page: number = 1;
  private pageSize: number = 10;
  public hasMoreData: boolean = false;

  constructor(
    public router: Router,
    public route: ActivatedRoute,
    public tools: ToolsService,
    public newService: NewsService,
    private _location: Location
  ) {
    this.route.params
      .switchMap((params: Params) => {
        this.tools.showLoading();
        this.articleId = params['articleId'];
        return this.newService.GetCateArticleListComment(this.articleId, this.page, this.pageSize);
      })
      .subscribe((res) => {
        this.tools.hideLoading();
        if (res && res.result === '0') {
          this.comments = [...res.data.list];
          // console.log(this.comments);
          this.page++;
          if (res.data.hasNextPage) {
            this.hasMoreData = true;
          }

        }
      });
  }

  goBack(): void {
    this._location.back();
  }

  ngOnInit() {

  }

}
